package nz.ac.massey.jbuif.view;

import static org.junit.Assert.assertEquals;

import java.util.Collection;
import java.util.Vector;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ListViewTest {

	ListView lv ;
	
	@Before
	public void setUp() throws Exception {
		lv = new ListView();
		lv.clearView();
	}

	@After
	public void tearDown() throws Exception {
		lv.clearView();
		lv = null;
	}

	@Test
	public void testClearView() {
		lv.clearView();
		assertEquals(0, lv.getModel().getSize());
	}

	@Test
	public void testGetSelectedObject() {
		Object obj = new Object();
		lv.setSelectedObject(obj);
		assertEquals(obj, lv.getSelectedObject());
		lv.clearView();
	}


	@Test
	public void testSort() {
		Collection<Object> objects = new Vector<Object>();
		
		objects.add("object 1");
		objects.add("object 0");

		lv.setView(objects);
		lv.sort();
		
		assertEquals ("object 0" ,lv.getModel().get(0));
		assertEquals ("object 1" ,lv.getModel().get(1));
	}

	@Test
	public void testFilterList() {
		Collection<Object> objects = new Vector<Object>();
		
		objects.add("nz.ac.massey.paper");
		objects.add("nz.ac.massey.address");

		lv.setView(objects);
		lv.filterList(".*\\.p.*");
//		System.out.println (lv.getModel().get(0));
		
		assertEquals ("nz.ac.massey.paper" , lv.getModel().get(0));
	}

}
